#ifndef SQLSETMANAGER_H
#define SQLSETMANAGER_H

#include <iostream>
#include <string>
#include <fstream>
#include <thread>
#include <list>
#include <unordered_map>
#include <chrono>
#include "../../include/rapidjson/document.h"
#include "sqlconnset.h"
#include "OCDatabaseMapper.h"
class OCDatabaseMapper;
class SqlSetManager
{
public:
    static SqlSetManager* getInstance();
    void addNewDB(std::string dbname);
    SqlConnSet* getSet(const std::string& db_name);
private:
    SqlSetManager();
    void readConf();
    void createSet(SqlSetManager* obj,std::string db_name);
    void monitorFunc(SqlSetManager* obj);
private:
    static std::string host;
    static std::string user;
    static std::string passwd;

    static int conf_min_num;
    static int conf_max_num;
    static int conf_free_time;
    static int conf_timeout;

    int db_num;
    std::list<SqlConnSet*> conn_list;
    std::unordered_map<std::string,SqlConnSet*> db_map;
    std::unordered_map<std::string,bool> status_map;
    SqlConnSet* tail_set;

    std::thread* manager_thread;

    static SqlSetManager manager;
};



#endif // SQLSETMANAGER_H
